package com.levy.contronller.jvm.classLoader;

/**
 * Created by levy on 2019/5/10.
 */
public class MyTest6 {

    public static void main(String[] args) {
        Singletom.getInstance();
        System.out.println("count1:" + Singletom.count1);
        System.out.println("count2:" + Singletom.count2);
    }

}

class Singletom {
    public static int count1;

    // count2的位置不同，代码的运行结果不同
    public static int count2 = 0;

    private static Singletom singletom = new Singletom();

    // count2的位置不同，代码的运行结果不同
    //    public static int count2 = 0;

    private Singletom() {
        count1++;
        count2++;
        System.out.println(count1);
        System.out.println(count2);
    }



    public static Singletom getInstance() {
        return singletom;
    }

}